import 'package:flutter/material.dart';

class NavigatorDemoWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            FlatButton(
              onPressed: () {
                Navigator.pushNamed(context, "/home");
              }, 
              child: Text("Home"),
            ),
            FlatButton(
              onPressed: () { // 控制页面路由跳转
                // Navigator.of(context).push(
                //   MaterialPageRoute(
                //     builder: (BuildContext context) => AboutPage(title: "About Page"),
                //   ),
                // );
                // 使用命名路由
                Navigator.pushNamed(context, "/about");
              }, 
              child: Text("About"),
            ),
          ],
        ),
      ),
    );
  }
}

class AboutPage extends StatelessWidget {

  final String title;

  AboutPage({ this.title });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
        elevation: 0.0,
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.arrow_back),
        onPressed: () { // 自定义返回事件
          Navigator.pop(context);
        },
      ),
    );
  }
}